
import java.io.*;
import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.filter.logging.MdcInjectionFilter;
import org.apache.mina.filter.ssl.SslFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import poplar.dp.net.ProtocolHandler;

public class Main {
	private static final int PORT = 8080;	
	
	public static void main(String[] args){		
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		acceptor.setHandler( new ProtocolHandler() );
		 
		DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();					
		chain.addLast( "logging", new LoggingFilter() );
		 
		try{			
			acceptor.bind( new InetSocketAddress(PORT) );
		 
			System.out.println( "Listening on port " + PORT );
			
			while( true ){
				//System.out.println( "R: " + acceptor.getReadBytesThroughput() + ", W: " + acceptor.getWrittenBytesThroughput() );
				Thread.sleep( 3000 );
			}
		}
		catch( InterruptedException ie ){
			System.out.println( ie.getMessage() );
		}
		catch( IOException ioe ){
			System.out.println( ioe.getMessage() );
		}
		catch( Exception e ){
			System.out.println( e.getMessage() );
		}
	}	
}
